package com.hospital.service.impl;

import com.hospital.dao.UserDao;
import com.hospital.entity.User;
import com.hospital.service.UserService;
import com.hospital.vo.ResponseVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

/**
 * 用户接口实现类
 * @author coder_zzm
 * @date 2022/5/22 16:11
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserDao userDao;

    /**
     * 用户注册
     * @param user 实体类
     * @return 是否注册成功
     */
    @Override
    public ResponseVO userRegistration(User user) {
        log.info("业务层注册用户");
        Integer result = userDao.userRegistration(user);
        if (result > 0) {
            return ResponseVO.buildSuccessInstance(ResponseVO.RESP_SUCCESS);
        }
        return ResponseVO.buildSuccessInstance(ResponseVO.UPDATE_FAIL);
    }

    /**
     * 用户登录
     * @param user 实体类
     * @return 是否登录成功
     */
    @Override
    public ResponseVO userLogin(User user) {
        User result = userDao.userLogin(user);
        if (result == null) {
            return ResponseVO.buildSuccessInstance(ResponseVO.RESP_SUCCESS);
        }
        return ResponseVO.buildSuccessInstance(ResponseVO.UPDATE_FAIL);
    }
}
